#include "head.h"

int changedir(command_t* command, char* path, int net_fd)
{
//printf("我在这里\n");
    char* path_head = "/home/yang/Database";
    char new_path[1024] = {0};
    strcpy(new_path, path_head);
    strcpy(new_path + strlen(path_head), command->path);
    strcpy(new_path + strlen(new_path), path);

    new_path[strlen(new_path)] = '/';
    struct stat stat_path;
//printf("%s\n", new_path);
    int type = 0;
    if(stat(new_path, &stat_path) == 0){
        if(S_ISDIR(stat_path.st_mode)){
            type = 1;
        }else{
            type = 0;
        }
    }else{
        type = -1;
    }
//printf("type: %d", type);
    int ret_send = send(net_fd, &type, sizeof(int), MSG_NOSIGNAL);
    if(ret_send < 0){
        return -1;
    }


    return 0;
}
